package C.e.collection;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;

/**集合转换为数组*/
public class CollectionToArray {
    public static void main(String[] args) {
        Collection<String>c=new ArrayList<>();
        c.add("one");
        c.add("two");
        c.add("three");
        c.add("four");
        c.add("five");
        System.out.println(c);//[one, two, three, four, five]

        //若参数数组元素个数==集合数组个数，那就正常转换
        //若参数数组元素个数<集合数组个数，那也就正常转换（按照基和大小给数组)
        //若参数数组元素个数>集合数组个数，那也就正常转换，同时在末尾补默认值（null）
        //String[]array=c.toArray(c.toArray(new String[6]));
        //String[]array=c.toArray(c.toArray(new String[5]));
        String[]array=c.toArray(c.toArray(new String[0]));
        System.out.println(Arrays.toString(array));//[one, two, three, four, five, null]
        // [one, two, three, four, five]
        //[one, two, three, four, five]

    }
}
